/**
 * @description 样式的选项
 */

import { getStyleListAPI } from "@/api/decoration"
export let styleOption = []
export let styleAttr = {}

export default async function initStyleData() {
  let res = await getStyleListAPI()

  let _styleAttr = {}
  let _styleOption = []

  res.data.list.forEach(item => {

    /**
     * 1. 样式的key 映射label名字
     * 在表单的label哪里显示
     * code: fontSize
     * code2: font-size
     */
    let code = item.code
    let code2 = code.replace(/([A-Z])/g, (match) => '-' + match.toLowerCase())
    let name = item.name
    _styleAttr[code] = name
    _styleAttr[code2] = name


    // 2. 添加新属性时，下拉列表
    _styleOption.push({
      value: code,
      label: <div className="style-option-wrapper">
        <span>{name}</span>
        <span className="code">{code}</span>
      </div>,
      name: name
    })
  })


  styleAttr = _styleAttr
  styleOption = _styleOption
}